#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sys/wait.h>

int main(void) {
	pid_t pid = fork ();
	if (-1 == pid) {
		perror ("fork()");
		return -1;
	}
	if (0 == pid) {
		//修改进程组
		setpgid (getpid(), getpid());
		printf ("child: pid = %d  pgid = %d sid = %d\n",\
				getpid(), getpgid(getpid()), getsid(getpid()));
		exit(0);
	}
	wait (NULL);
	printf ("child: pid = %d  pgid = %d sid = %d\n",\
			getpid(), getpgid(getpid()), getsid(getpid()));
	return 0;
}
